package MyServlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Dao.HospitalDao;
import MyBean.patient;
import factory.HospitalFactory;

/**
 * Servlet implementation class insertProgram
 */

public class insertPatient extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public insertPatient() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		patient patient1 = new patient(
				request.getParameter("admissionNumber"),
				request.getParameter("patientName"),
				request.getParameter("sex"),
				request.getParameter("age"),
				request.getParameter("patientNumber"),
				request.getParameter("phone"),
				request.getParameter("roomno"),
				request.getParameter("startTime")
				);
		try {
			HospitalDao hd = HospitalFactory.getProxy();
			if(hd.insertPatient(patient1))
			{
				request.setAttribute("patient2",patient1);
				RequestDispatcher dispatcher = request.getRequestDispatcher("applySuccess.jsp");
				dispatcher.forward(request, response);
				
			}
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
